xen/passthrough: Support a single iommu_domain per xen domain per SMMU
authorRobbie VanVossen <robert.vanvossen@dornerworks.com>
Tue, 24 Mar 2015 20:48:19 +0000 (16:48 -0400)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 31 Mar 2015 10:22:58 +0000 (11:22 +0100)
commite502f628437e6bd156b7d57b203276f9db5a13b6
tree0e65e74b4345d21f05a86dd52762e857ae494f2b
parentceb7d6b66de21810a837389911eb2f40c1ca6222
xen/passthrough: Support a single iommu_domain per xen domain per SMMU

If multiple devices are being passed through to the same domain and they
share a single SMMU, then they only require a single iommu_domain.

In arm_smmu_assign_dev, before a new iommu_domain is created, the
xen_domain->contexts is checked for any iommu_domains that are already
assigned to device that uses the same SMMU as the current device. If one
is found, attach the device to that iommu_domain. If a new one isn't
found, create a new iommu_domain just like before.

The arm_smmu_deassign_dev function assumes that there is a single
device per iommu_domain. This meant that when the first device was
deassigned, the iommu_domain was freed and when another device was
deassigned a crash occurred in xen.

To fix this, a reference counter was added to the iommu_domain struct.
When an arm_smmu_xen_device references an iommu_domain, the
iommu_domains ref is incremented. When that reference is removed, the
iommu_domains ref is decremented. The iommu_domain will only be freed
when the ref is 0.

Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
Reviewed-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen/drivers/passthrough/arm/smmu.c